package com.lmc.chatroom.service;

import com.lmc.chatroom.mapper.userMapper;
import com.lmc.chatroom.model.User;
import com.lmc.chatroom.utils.SecurityUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class userService {

    @Autowired
    userMapper userMapper;

//    public boolean login(String username, String password) {
//
//        if(userMapper.login(username,  password)!=null){
//            return true;
//        }
//        return false;
//    }

    public boolean register(String username, String password) {
        log.info("register");
        String encryptedPassword = SecurityUtil.encryptPassword(password);
        if (userMapper.register(username, encryptedPassword)>0) {
            return true;
        }
        return false;
    }

    public User selectByUsername(String username) {
        log.info("selectByUsername");
        return userMapper.selectByUsername(username);
    }
}
